package com.cccyy.data.jsondata;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.LinkedHashSet;
import java.util.List;

public class DataCollationAndDeduplication {
    public static void main(String[] args) throws Exception {
        String filePath = "D:\\WorkSpace\\Study\\study-test\\src\\main\\java\\com\\cccyy\\data\\jsondata\\Data.txt";
        LinkedHashSet<String> names = getData(filePath);
        StringBuilder stringBuilder = new StringBuilder();
        for (String name : names) {
            stringBuilder.append(name).append("，");
        }
        System.out.println(stringBuilder);
    }

    public static LinkedHashSet<String> getData(String filePath) throws Exception {
        //读取每行数据 存入set中 去重
        //文件里面 是普通文本
        List<String> lines = Files.readAllLines(Paths.get(filePath), StandardCharsets.UTF_8);
        LinkedHashSet<String> objects = new LinkedHashSet<>();
        for (String line : lines) {
            if (objects.contains(line)) {
                continue;
            }
            objects.add(line);
        }
        return objects;
    }
}
